package com.xinruke.hostels.support.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.support.generator.po.SysDiqu;
import com.xinruke.hostels.support.interfaces.dto.RegionQueryDto;
import com.xinruke.hostels.support.interfaces.dto.RegionQueryResultDto;
import com.xinruke.hostels.support.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author GuoZheng
 * @ClassName RegionController
 * @date：2019/6/19
 * @version: V1.0.0
 * @description：地区
 */
@RestController
@RequestMapping("/region")
@Api(tags = "地区")
public class RegionController extends BaseController {
    @Resource
    private RegionService regionService;
    /**
     * 获取地区列表，
     * parentId:上一级的地区id，0是获取顶级地区信息
     *
     * @param params
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("获取地区列表")
    public ResultVO<List<RegionQueryResultDto>> region(@RequestBody RegionQueryDto params) {
        return  regionService.regionList(params);
    }

    /**
     * 查询地区信息根据地区名称
     *
     * @return
     */
    @ResponseBody
    @ApiIgnore
    @RequestMapping(value = "/getAreaInfoByAreaName.json", method = RequestMethod.POST)
    @ApiOperation("根据地区名称获取地区信息")
    public ResultVO getAreaByAreaName(@RequestBody SysDiqu sysDiqu) {
        if (StringUtils.isBlank(sysDiqu.getMingcheng())) {
            return new ResultVO(ResultVO.FAIL,"地区名称为空");
        }
        Map resultMap = regionService.getSysDiquInfoByAreaName(sysDiqu);
        if (resultMap != null) {
            return new ResultVO(ResultVO.SUCCESS,"成功", resultMap);
        }
        return new ResultVO(ResultVO.FAIL,"获取失败");
    }

    /**
     * 查询所有地区列表
     *
     * @return
     */
    @ResponseBody
    @ApiIgnore
    @RequestMapping(value = "/areaAllList.json", method = RequestMethod.POST)
    @ApiOperation("获取所有地区列表")
    public ResultVO getAreaAllList() {
        return new ResultVO(ResultVO.SUCCESS,"成功", regionService.getSysDiquAllList());
    }

}
